
import {Iaction} from '../../utils/interface';

const initialState={
    topicList:[],
    detailInfo:{},
    relatedList:[],
    leaveInfo:{},
}
const actions:{[key:string]:Function}={
    'INIT_TOPIC':(state:any,action:Iaction)=>{
        state = Object.assign(state,{topicList:action.payload})
    },
    'INIT_DETAIL':(state:any,action:Iaction)=>{
        state = Object.assign(state,{detailInfo:action.payload})
    },
    'INIT_RELATEDS':(state:any,action:Iaction)=>{
        state = Object.assign(state,{relatedList:action.payload})
    },
    'INIT_LEAVE':(state:any,action:Iaction)=>{
        state = Object.assign(state,{leaveInfo:action.payload})
    }
}
const reducer = (state=initialState,action:Iaction)=>{
    const newState = JSON.parse(JSON.stringify(state));
    actions[action.type] && actions[action.type](newState,action);
    return newState
}

export default reducer